//
// Created by 67678 on 2023/3/12.
//

#ifndef WEBSERVER_SOCKETCLIENT_H
#define WEBSERVER_SOCKETCLIENT_H

#include <string>
#include <mutex>

namespace socket_epoll {

class SocketClient {
public:
    SocketClient();

    int connect(int ip, int port);

    void init(int fd);

    void setNonBlocking();

    int write(std::string_view sv);

    std::string read();

    void close();

    int getFD() const;

    ~SocketClient();

private:
    int blockingWrite(std::string_view sv);

    int nonBlockingWrite(std::string_view sv);

    std::string blockingRead();

    std::string nonBlockingRead();


    bool blocking_ = true;
    int socket_ = -1;
};
}
#endif //WEBSERVER_SOCKETCLIENT_H
